package com.example.administrator.funchat.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.funchat.model.Info_information;
import com.example.administrator.funchat.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息界面适配器
 * Created by Administrator on 2016/6/23.
 */
public class InformationAdapter extends ArrayAdapter<Info_information> {


    private int resourceId;
    private List<Info_information> infolist = new ArrayList<>();

    public InformationAdapter(Context context, int resource) {
        super(context, resource);
        this.resourceId = resource;
    }

    @Override
    public int getCount() {
        return infolist.size();
    }

    @Override
    public Info_information getItem(int position) {
        return infolist.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Info_information information = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
            viewHolder = new ViewHolder();
            viewHolder.infoImage = (ImageView) view.findViewById(R.id.info_image);
            viewHolder.infoFrom = (TextView) view.findViewById(R.id.info_from);
            viewHolder.endInfo = (TextView) view.findViewById(R.id.end_info);
            viewHolder.endInfoTime = (TextView) view.findViewById(R.id.end_info_time);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }


        viewHolder.infoImage.setImageResource(information.getImageId());
        viewHolder.infoFrom.setText(information.getMessage_source());
        viewHolder.endInfo.setText(information.getEnd_message());
        viewHolder.endInfoTime.setText(information.getEnd_message_time());
        return view;
    }

    class ViewHolder {
        ImageView infoImage;
        TextView infoFrom;
        TextView endInfo;
        TextView endInfoTime;
    }

    //初始化信息Tab数据
    public void load() {
        Info_information aiqiyi = new Info_information("爱奇艺视频", "中国特警会阿根廷华人帮啊啊啊啊啊啊啊啊啊啊啊", "8:00", R.mipmap.aiqiyi_icon);
        infolist.add(aiqiyi);
        Info_information man = new Info_information("好友1", "呵呵哒", "8:00", R.mipmap.man_icon);
        infolist.add(man);
        Info_information youxiang = new Info_information("QQ邮箱", "好友生日快到了", "12:00", R.mipmap.youxiang_icon);
        infolist.add(youxiang);
        Info_information haoyou01 = new Info_information("爱奇艺视频", "中国特警会阿根廷华人帮啊啊啊啊啊啊啊啊啊啊啊", "8:00", R.mipmap.aiqiyi_icon);
        infolist.add(haoyou01);
        Info_information haoyou02 = new Info_information("好友1", "呵呵哒", "8:00", R.mipmap.man_icon);
        infolist.add(haoyou02);
        Info_information haoyou03 = new Info_information("QQ邮箱", "好友生日快到了", "12:00", R.mipmap.youxiang_icon);
        infolist.add(haoyou03);
        Info_information haoyou004 = new Info_information("爱奇艺视频", "中国特警会阿根廷华人帮啊啊啊啊啊啊啊啊啊啊啊", "8:00", R.mipmap.aiqiyi_icon);
        infolist.add(haoyou004);
        Info_information haoyou05 = new Info_information("好友1", "呵呵哒", "8:00", R.mipmap.man_icon);
        infolist.add(haoyou05);
        Info_information haoyou006 = new Info_information("QQ邮箱", "好友生日快到了", "12:00", R.mipmap.youxiang_icon);
        infolist.add(haoyou006);
    }

}
